#ifdef ELS_OS_LINUX 
#include<stdio.h>
#include<stdlib.h>
#include "els.h"
#define ELS_VERSION	"EasyLosu v1.6.4  Linux Branch"
#define ELS_COPYRIGHT	"MIT LICENSE  2022-2023 easylosu@lists.openkylin.top"
#define ELS_BUILD ("build ("__DATE__","__TIME__") [GCC ")
extern int maxsize,subsize;
static int els_argc;
static char **els_argv;

#if defined ELS_OS_LINUX || defined ELS_OS_WINDOWS 
int els_getargv (els_VmObj *l){
    if (!els_isnum(l,1)) els_pushnull(l);
    else{
        int n = (int)els_getnum(l,1);
        if (n > els_argc-2) els_pushstr(l,"");
        else els_pushstr(l,els_argv[n+1]);
    }
    return 1;
}
int els_getargc (els_VmObj *l){
    els_pushnum(l,els_argc-2);
    return 1;
}
#endif


int main (int argc, char **argv){
    els_VmObj *l=els_createvm(512);
    int s;
    els_argc = argc;
    els_argv = argv;
    #if defined ELS_OS_LINUX || defined ELS_OS_WINDOWS 
    els_register(l,"argv", els_getargv);
    els_register(l,"argc", els_getargc);
    #endif
    els_lib_init(l);
    if (argc < 2){
        printf("%s\n%s\n%s%d.%d.%d]\n",ELS_VERSION,ELS_COPYRIGHT,ELS_BUILD,__GNUC__ ,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);
        return 0;
    }else{
        els_dostring(l,"import('std')\n");
        s =  els_dofile (l,argv[1]);
    }
    els_closevm(l);
    return s;
}
#endif

#ifdef ELS_OS_WINDOWS
#include<stdio.h>
#include<stdlib.h>
#include "els.h"
#define ELS_VERSION	"EasyLosu v1.6.4  Windows Branch"
#define ELS_COPYRIGHT	"MIT LICENSE  2022-2023 easylosu@lists.openkylin.top"
#define ELS_BUILD ("build ("__DATE__","__TIME__") [GCC ")
extern int maxsize,subsize;
static int els_argc;
static char **els_argv;

#if defined ELS_OS_LINUX || defined ELS_OS_WINDOWS 
int els_getargv (els_VmObj *l){
    if (!els_isnum(l,1)) els_pushnull(l);
    else{
        int n = (int)els_getnum(l,1);
        if (n > els_argc-2) els_pushstr(l,"");
        else els_pushstr(l,els_argv[n+1]);
    }
    return 1;
}
int els_getargc (els_VmObj *l){
    els_pushnum(l,els_argc-2);
    return 1;
}
#endif

char* els_lib_win_togbk(const char * str);
char* els_lib_win_toutf8(const char* str);
int main (int argc, char **argv){
    els_VmObj *l=els_createvm(512);
    int s;
    els_argc = argc;
    els_argv = argv;
    #if defined ELS_OS_LINUX || defined ELS_OS_WINDOWS 
    els_register(l,"argv", els_getargv);
    els_register(l,"argc", els_getargc);
    #endif
    els_lib_init(l);
    els_dostring(l,"import('std')\nimport('stdfile')\nimport('stdmath')\nimport('stdstring')\nimport('stdsys')\nimport('stdtime')\n");
    if (argc < 2){
        printf("%s\n%s\n%s%d.%d.%d]\n",ELS_VERSION,ELS_COPYRIGHT,ELS_BUILD,__GNUC__ ,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);
        printf("----------------------------------------------------------------\n");
        char tmp[1024];
        char *tmp2;
        while(1){
            printf(">>>>");
            gets(tmp);
            tmp2 = els_lib_win_toutf8(tmp);
            els_dostring(l,tmp2);
            free(tmp2);
        }
        return 0;
    }else{
        s =  els_dofile (l,argv[1]);
    }
    els_closevm(l);
    return s;
}

#endif